package com.ericsson.rm.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.ericsson.rm.model.ProjectResourceDetail;
import com.ericsson.rm.response.ResourceProjectResponse;
import com.ericsson.rm.vo.ProjectResourceDetailVO;

@Repository
public class ProjectResourceDaoImpl implements ProjectResourceDao {

	/*@Autowired
	EntityManagerFactory factory;*/

	@PersistenceContext
	EntityManager entityManager;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ResourceProjectResponse> fetchResourceProjectInDateRange(
			String startDate, String endDate) {
		//EntityManager entity = factory.createEntityManager();
		Query q = entityManager.createNamedQuery(
				"ProjectResourceDetail.findProjectResourceId",
				ProjectResourceDetail.class);
		return q.getResultList();
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<ProjectResourceDetail> fetchProjectResourceDetailFromDB(String projId)
	{
		Query q = entityManager.createNamedQuery(
				"ProjectResourceDetail.getdetailsbyProjId", ProjectResourceDetail.class).setParameter("projId", projId);
		return q.getResultList();
	}

	
	
	
	
	
	public EntityManager getEntityManager() {
		return entityManager;
	}

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}
	
}
